﻿<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="OtherProject.aspx.vb" Inherits="OtherProject" %>

<%@ Register Assembly="ISNet.WebUI.WebTreeView" Namespace="ISNet.WebUI.WebTreeView" TagPrefix="ISWebTreeView" %>

<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>

<%@ Register Assembly="ISNet.WebUI.WebCombo" Namespace="ISNet.WebUI.WebCombo" TagPrefix="ISWebCombo" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:HiddenField ID="HD_FundCombo" runat="server" />
    <style type="text/css">
        .EditCellColor {
            background-color: #ffffcc !important;
        }
    </style>
    <link href="js/magicsuggest-1.2.6.css" rel="stylesheet" />
    <script src="js/magicsuggest-1.2.6.js"></script>
    <script src="script/packed.js"></script>
    <script src="script/tinybox.js"></script>
    <link href="script/style.css" rel="stylesheet" />
    <script type="text/javascript" src="js/JSON.js"></script>
    <script type="text/javascript">
        var dfc = 'null';
        var dfcname = '';
        <%= dfctr%>

        var CmtList = new Array();
        <%= CmtTxt%>
        var UnitList = new Array();
        <%= CmtUnit%>
        var Default1List = new Array();
        <%= Default1%>
        var Default2List = new Array();
        <%= Default2%>
        var Default3List = new Array();
        <%= Default3%>
        function openJS() { alert('loaded') }
        function closeJS() { doupdate() }
        function closeJS2() { doupdate() }
        function doupdate() {
            var grid = ISGetObject("WebGrid1");
            grid.ClearSelectedObject();
            grid.RootTable.UpdateUI();
            grid.RefreshAll();

        }
        function popupattach1() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();



            //get the key value of selected row.
            var key = row.KeyValue;

            TINY.box.show({ iframe: 'neatupload.aspx?BDID=' + key, boxid: 'frameless', width: 540, height: 450, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });




        }
        function popupattach2() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            var key = row.KeyValue;

            //get the key value of selected row.
            TINY.box.show({ iframe: 'AttachmentListPopup.aspx?BDID=' + key, boxid: 'frameless', width: 350, height: 250, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS2() } })
        }
    </script>

    <script>
        function WebGrid1_OnAfterExitEditMode(controlId, tblName, editObject) {

            var WebGrid1 = ISGetObject(controlId);
            var rootTable = WebGrid1.RootTable;
            var cell = wgGetCellByElement(editObject.cellElement);
            var colName = cell.Name;

            var cellsplit = cell.Value.toString().split(".");

            if (cellsplit[1] !== undefined && cellsplit[1].length > 2) {
                cell.SetText(cell.Text, true);
            }

            //if (colName == "Element2") {
            //    var cellval2 = 0;
            //    cellval2 = cell.Value;
            //    if (cellval2 % 1 != 0) {
            //        alert("ให้บันทึกค่าเป็นจำนวนเต็มเท่านั้น");
            //    }
            //}

            if (colName != "Note" && colName != "FundCenter" && colName != "CommitmentItem" && colName != "CmmtDetail" && colName != "Project" && colName != "Identification" && colName != "Unit1" && colName != "Unit2" && colName != "Unit3") {
                var cellval = 0;
                cellval = cell.Value;
                if (cellval + '' == "NaN" || cellval == 0) {
                    cell.SetText("0.00", true);
                }
            }

            if (colName == "Element1" || colName == "Element2") {
                var roundval = parseFloat(cell.Value.replace(/\,/g, ''));
                roundval = Math.round(roundval);
                cell.SetText(String(roundval).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
            }

            var row = cell.Row;
            var htmlRow = row.GetElement();
            try {
                var rows = WebGrid1.GetSelectedObject().GetRowObject(); // get WebGridRow object by key value.
                var cells = rows.GetCells()
                //var note = cells.GetNamedItem("Note");
                //var flag = note.GetElement().attributes["readonly_flag"].value;
                var cmtval = "";
                //var CmmtDetailCombo = ISGetObject("CmmtDetailCombo");
                //cmtval = CmmtDetailCombo.Value;
                //if (cmtval.toString() == "") {
                    cmtval = row.GetCells().GetNamedItem("CmmtDetail").Value
                //}
                var cmtpat = CmtList[cmtval];
                var flag = cmtpat;
                //alert(flag);

                //note.GetElement().attributes["readonly_flag"].value = "2,2,2,2"
                //flag = note.GetElement().attributes["readonly_flag"].value;
                //alert(flag);
                var readonly = flag.substring(2);
                //alert(readonly);
                var num1 = parseFloat((wgGetCellByPosition(htmlRow, 6).innerText).replace(/\,/g, ''));
                var num2 = parseFloat((wgGetCellByPosition(htmlRow, 8).innerText).replace(/\,/g, ''));
                var num3 = parseFloat((wgGetCellByPosition(htmlRow, 10).innerText).replace(/\,/g, ''));

                if (num1 + '' == "NaN" || num1 == 0) {
                    num1 = 0;
                }
                if (num2 + '' == "NaN" || num2 == 0) {
                    num2 = 0;
                }
                if (num3 + '' == "NaN" || num3 == 0) {
                    num3 = 0;
                }

                var result;
                var setflag = 1;
                if (readonly == '1,1,1') {
                    result = num1 * num2 * num3;
                }
                else if (readonly == '1,1,0') {
                    result = num1 * num2;
                }
                else if (readonly == '1,0,1') {
                    result = num1 * num3;
                }
                else if (readonly == '0,1,1') {
                    result = num2 * num3;
                }
                else {
                    setflag = 0;
                }

                if (setflag == 1) {
                    result = result.toFixed(2);

                    if (result + '' == "NaN" || result == 0) {
                        result = 0;
                    }

                    var rcell = row.GetCell("SumEl");
                    rcell.SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);

                } else {
                    var numsum = parseFloat((wgGetCellByPosition(htmlRow, 12).innerText).replace(/\,/g, ''));
                    result = numsum;
                    result = result.toFixed(2);

                    if (result + '' == "NaN" || result == 0) {
                        result = 0;
                    }
                }

                var result2 = Math.ceil(result / 100) * 100;
                result2 = result2.toFixed(2);

                if (result2 + '' == "NaN" || result2 == 0) {
                    result2 = 0;
                }
                var final = parseFloat((result2));
                final = final.toFixed(2)
                var rcell2 = row.GetCell("Amount");
                rcell2.SetText(String(final).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true)

                ////column pattern

                var row1 = WebGrid1.GetSelectedObject().GetRowObject();
                //var CmmtDetailCombo1 = ISGetObject("CmmtDetailCombo");
                var cmtval1 = row1.GetCells().GetNamedItem("CmmtDetail").Value
                //alert(CmtList[cmtval]);
                var cells1 = row1.GetCells();

                var cmtpat1 = CmtList[cmtval1];
                var columnindex = 6;
                var cmtarrs = cmtpat1.toString().split(",");

                var read_count = 0;
                var unitpat = UnitList[cmtval1];
                var unitarrs = unitpat.toString().split(",");

                for (i = 1; i <= 3; i++) {
                    if (cmtarrs[i] == '1') {
                        var patcells = cells1[columnindex];
                        patcells.SetForceNoEdit(false);

                        var cellCSS = patcells.GetElement().className;
                        patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
                        patcells.GetElement().className += " EditCellColor";
                        read_count = read_count + 1;
                    }
                    else {
                        var patcells = cells1[columnindex];
                        patcells.SetForceNoEdit(true);

                        var cellCSS = patcells.GetElement().className;
                        patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
                    }
                    //alert(unitarrs[i - 1]);
                    var patcells2 = cells1[columnindex + 1];
                    //row.GetCells().GetNamedItem("Unit1").SetForceNoEdit(false);
                    //row.GetCells().GetNamedItem("Unit1").SetText(unitarrs[i - 1], true);
                    patcells2.SetText(unitarrs[i - 1], true);
                    patcells2.SetForceNoEdit(true);
                    columnindex = columnindex + 2;
                }
                if (read_count == 0) {
                    var cellCSS = cells1[12].GetElement().className;
                    cells1[12].SetForceNoEdit(false);
                    cells1[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                    cells1[12].GetElement().className += " EditCellColor";
                }
                else {
                    cells1[12].SetForceNoEdit(true);
                    cells1[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                }

                var df3 = Default3List[cmtval1];
                if (df3 > 0) {
                    row1.GetCells().GetNamedItem("Element3").SetText(df3, true);
                    row1.GetCells().GetNamedItem("Element3").SetForceNoEdit(true);
                }

                //alert(cmtval1);
            }
            catch (err) {

            }
            return true;


        }
        function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject) {
            menuObject.Items[0].Hide();

            return false;
        }
        function FundCenterCombo_OnAfterItemSelected(controlId) {


            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();

            var cells = row.GetCells();

            row.GetCells().GetNamedItem("Element1").SetText("0", true);
            row.GetCells().GetNamedItem("Element2").SetText("0", true);
            row.GetCells().GetNamedItem("Element3").SetText("0", true);
            row.GetCells().GetNamedItem("Unit1").SetText("", true);
            row.GetCells().GetNamedItem("Unit2").SetText("", true);
            row.GetCells().GetNamedItem("Unit3").SetText("", true);
            row.GetCells().GetNamedItem("SumEl").SetText("", true);
            row.GetCells().GetNamedItem("Amount").SetText("", true);

            var code_combo = ISGetObject("ProjectCombo");
            code_combo.ClearSelection();
            code_combo.Value = "";
            code_combo.SetTextBoxValue("");
            row.GetCells().GetNamedItem("Project").SetText("", true);

            var code_combo2 = ISGetObject("CmmtCombo");
            code_combo2.ClearSelection();
            code_combo2.Value = "";
            code_combo2.SetTextBoxValue("");
            row.GetCells().GetNamedItem("CommitmentItem").SetText("", true);

            var code_combo2 = ISGetObject("CmmtDetailCombo");
            code_combo2.ClearSelection();
            code_combo2.Value = "";
            code_combo2.SetTextBoxValue("");
            row.GetCells().GetNamedItem("CmmtDetail").SetText("", true);

        }


        function CmmtCombo_OnAfterItemSelected(controlId) {


            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();

            row.GetCells().GetNamedItem("Element1").SetText("0", true);
            row.GetCells().GetNamedItem("Element2").SetText("0", true);
            row.GetCells().GetNamedItem("Element3").SetText("0", true);
            row.GetCells().GetNamedItem("Unit1").SetText("", true);
            row.GetCells().GetNamedItem("Unit2").SetText("", true);
            row.GetCells().GetNamedItem("Unit3").SetText("", true);
            row.GetCells().GetNamedItem("Amount").SetText("", true);

            var code_combo = ISGetObject("CmmtDetailCombo");
            code_combo.ClearSelection();
            code_combo.Value = "";
            code_combo.SetTextBoxValue("");
            row.GetCells().GetNamedItem("CmmtDetail").SetText("", true);

        }

        function CmmtDetailCombo_OnAfterItemSelected(controlId) {
            //alert("cmmt");

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            var CmmtDetailCombo = ISGetObject("CmmtDetailCombo");
            var cmtval = CmmtDetailCombo.Value;
            row.GetCells().GetNamedItem("Element1").SetText("0", true);
            row.GetCells().GetNamedItem("Element2").SetText("0", true);
            row.GetCells().GetNamedItem("Element3").SetText("0", true);
            row.GetCells().GetNamedItem("Unit1").SetText("", true);
            row.GetCells().GetNamedItem("Unit2").SetText("", true);
            row.GetCells().GetNamedItem("Unit3").SetText("", true);
            row.GetCells().GetNamedItem("Amount").SetText("", true);

            //alert(CmtList[cmtval]);
            var cells = row.GetCells();

            var cmtpat = CmtList[cmtval];
            var columnindex = 6;
            var cmtarrs = cmtpat.toString().split(",");

            var read_count = 0;
            var unitpat = UnitList[cmtval];
            var unitarrs = unitpat.toString().split(",");

            for (i = 1; i <= 3; i++) {
                if (cmtarrs[i] == '1') {
                    var patcells = cells[columnindex];
                    patcells.SetForceNoEdit(false);

                    var cellCSS = patcells.GetElement().className;
                    patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
                    patcells.GetElement().className += " EditCellColor";
                    read_count = read_count + 1;
                }
                else {
                    var patcells = cells[columnindex];
                    patcells.SetForceNoEdit(true);

                    var cellCSS = patcells.GetElement().className;
                    patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
                }
                //alert(unitarrs[i - 1]);
                var patcells2 = cells[columnindex + 1];
                //row.GetCells().GetNamedItem("Unit1").SetForceNoEdit(false);
                //row.GetCells().GetNamedItem("Unit1").SetText(unitarrs[i - 1], true);
                patcells2.SetText(unitarrs[i - 1], true);
                patcells2.SetForceNoEdit(true);
                columnindex = columnindex + 2;
            }
            if (read_count == 0) {
                var cellCSS = cells[12].GetElement().className;
                cells[12].SetForceNoEdit(false);
                cells[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                cells[12].GetElement().className += " EditCellColor";
            }
            else {
                cells[12].SetForceNoEdit(true);
                cells[12].GetElement().className = cellCSS.replace("EditCellColor", "");
            }

            var df3 = Default3List[cmtval];
            if (df3 > 0) {
                row.GetCells().GetNamedItem("Element3").SetText(df3, true);
                row.GetCells().GetNamedItem("Element3").SetForceNoEdit(true);
            }

            //var rrows = grid.GetSelectedObject().GetRowObject();
            //var rcells = rrows.GetCells()
            //var rnote = rcells.GetNamedItem("Note");
            //rnote.GetElement().attributes["readonly_flag"].value = cmtpat;

        }

        function OnRowSelect(controlId, tblName, rowIndex, rowElm) {


            var grid = ISGetObject("WebGrid1");
            var ar = grid.GetSelectedObject().GetRowElement
            var row = grid.GetSelectedObject().GetRowObject();
            row.GetCells().GetNamedItem("Amount").SetForceNoEdit(true);
            row.GetCells().GetNamedItem("Unit1").SetForceNoEdit(true);
            row.GetCells().GetNamedItem("Unit2").SetForceNoEdit(true);
            row.GetCells().GetNamedItem("Unit3").SetForceNoEdit(true);
            if (grid.GetSelectedObject().GetRowObject().Type == "NewRow") {
                if (dfc != 'null') {
                    row.GetCells().GetNamedItem("FundCenter").SetText(dfcname, true);
                    row.GetCells().GetNamedItem("FundCenter").SetValue(dfc);
                }
            }
            if (ar.IsAddNewRow) {
            }
            else {


                row.GetCells().GetNamedItem("Attachment").SetForceNoEdit(true);

                var combo = ISGetObject("FundCenterCombo");
                var Val = row.GetCells().GetNamedItem("FundCenter").Value
                if (combo != undefined)
                    combo.SetValue(Val);

                var combo2 = ISGetObject("CmmtCombo");
                var Val2 = row.GetCells().GetNamedItem("CommitmentItem").Value
                if (combo2 != undefined)
                    combo2.SetValue(Val2);

                //var ar = grid.GetSelectedObject().GetRowElement();

                //if (ar.IsAddNewRow) {
                //    var cells = row.GetCells();
                //    for (i = 6; i <= 13; i++) {
                //        var patcells = cells[i];
                //        patcells.SetForceNoEdit(true);
                //    }
                //}
                //try {
                //    var cmtval = "";
                //    var CmmtDetailCombo = ISGetObject("CmmtDetailCombo");
                //    cmtval = CmmtDetailCombo.Value;
                //    if (cmtval.toString() == "") {
                //        cmtval = row.GetCells().GetNamedItem("CmmtDetail").Value
                //    }

                //    var cmtpat = CmtList[cmtval];
                //    //alert(cmtpat);
                //    var columnindex = 6;
                //    var cmtarrs = cmtpat.toString().split(",");

                //    var read_count = 0;
                //    var cells = row.GetCells();
                //    for (i = 1; i <= 3; i++) {
                //        if (cmtarrs[i] == '1') {
                //            var patcells = cells[columnindex];

                //            patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
                //            patcells.GetElement().className += " EditCellColor";
                //            read_count = read_count + 1;
                //        }
                //        else {
                //            var patcells = cells[columnindex];

                //            var cellCSS = patcells.GetElement().className;
                //            patcells.GetElement().className = cellCSS.replace("EditCellColor", "");

                //        }
                //        //alert(unitarrs[i - 1]);
                //        var patcells2 = cells[columnindex + 1];
                //        //row.GetCells().GetNamedItem("Unit1").SetForceNoEdit(false);
                //        //row.GetCells().GetNamedItem("Unit1").SetText(unitarrs[i - 1], true);
                //        columnindex = columnindex + 2;
                //    }
                //    if (read_count == 0) {
                //        var cellCSS = cells[12].GetElement().className;
                //        cells[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                //        cells[12].GetElement().className += " EditCellColor";
                //    }
                //    else {
                //        cells[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                //    }
                //}
                //catch (err) {
                //    //alert(err);
                //}


            }


            //var rowObj = grid.GetSelectedObject().GetRowObject();
            //var cells = rowObj.GetCells();
            //for (i = 4; i <= 7; i++) {
            //    // row.GetCells().GetNamedItem("Amount").GetElement().style.borderColor = "red";
            //    //row.GetCells().GetNamedItem("Amount").GetElement().style.color = "red";
            //    cells[i].GetElement().className += " EditCellColor";
            //    // row.GetCells().GetNamedItem("Amount").GetElement().style. BorderSettings-Top-Style="Solid"

            //}
        }

        function OnBeforeRowSelect(controlId, tblName, rowIndex, rowElm) {


            var grid = ISGetObject("WebGrid1");

            try {
                var rowObj = grid.GetSelectedObject().GetRowObject();


                if (rowObj != null) {
                    var cmtval = "";
                    //var CmmtDetailCombo = ISGetObject("CmmtDetailCombo");
                    //cmtval = CmmtDetailCombo.Value;
                    //if (cmtval.toString() == "") {
                    cmtval = rowObj.GetCells().GetNamedItem("CmmtDetail").Value
                    //}

                    var cmtpat = CmtList[cmtval];
                    var columnindex = 6;
                    var cmtarrs = cmtpat.toString().split(",");

                    var read_count = 0;
                    var cells = rowObj.GetCells();
                    for (i = 1; i <= 3; i++) {
                        if (cmtarrs[i] == '1') {
                            var patcells = cells[columnindex];

                            patcells.GetElement().className += " EditCellColor";
                            read_count = read_count + 1;
                        }
                        else {
                            var patcells = cells[columnindex];

                            var cellCSS = patcells.GetElement().className;
                            patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
                        }
                        //alert(unitarrs[i - 1]);
                        var patcells2 = cells[columnindex + 1];
                        //row.GetCells().GetNamedItem("Unit1").SetForceNoEdit(false);
                        //row.GetCells().GetNamedItem("Unit1").SetText(unitarrs[i - 1], true);
                        columnindex = columnindex + 2;
                    }
                    if (read_count == 0) {
                        var cellCSS = cells[12].GetElement().className;
                        cells[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                        cells[12].GetElement().className += " EditCellColor";
                    }
                    else {
                        cells[12].GetElement().className = cellCSS.replace("EditCellColor", "");
                    }

                }
            }
            catch (err) {
                //alert(err);

            }

        }

        function WebGrid1_OnRowValidate(rowObject) {
            // retrieves WebGrid's object
            var grid = ISGetObject("WebGrid1");

            // access WebGrid's RootTable
            var rootTable = grid.RootTable;

            var row = rootTable.ToRowObject(rowObject); // convert the rowObject (HTMLElement) to WebGridRow object
            var htmlRow = row.GetElement();
            var cells = row.GetCells(); // get collection of WebGridCell
            var error = 0;
            var err_text = "กรุณาตรวจสอบ \n"

            //alert("1");
            var data
            data = wgGetCellByPosition(htmlRow, 1).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n   ● FundCenter";
                error = error + 1;
            }

            data = wgGetCellByPosition(htmlRow, 2).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n   ● Commitment Item";
                error = error + 1;
            }

            data = wgGetCellByPosition(htmlRow, 3).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n   ● รายการ";
                error = error + 1;
            }

            data = wgGetCellByPosition(htmlRow, 4).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n   ● โครงการ";
                error = error + 1;
            }


            //alert(cmtpat.substring(0,1));
            data = wgGetCellByPosition(htmlRow, 5).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                try {
                    var cmtval = "";
                    var CmmtDetailCombo = ISGetObject("CmmtDetailCombo");
                    cmtval = CmmtDetailCombo.Value;
                    if (cmtval.toString() == "") {
                        cmtval = row.GetCells().GetNamedItem("CmmtDetail").Value
                    }
                    var cmtpat = CmtList[cmtval];
                    if (cmtpat.substring(0, 1) == '1') {
                        err_text = err_text + "\n   ● Identification";
                        error = error + 1;
                    }
                }
                catch (err) {

                }

            }

            var versionTxt = document.getElementById('<%=VersionTxt.ClientID%>').value;
            versionTxt = versionTxt.trim();
            var amount = parseFloat((wgGetCellByPosition(htmlRow, 13).innerText).replace(/\,/g, ''));
            data = wgGetCellByPosition(htmlRow, 13).innerText;
            if (((versionTxt == '1' || versionTxt == '2' || versionTxt == '3' || versionTxt == '4' || versionTxt == '5') && (amount <= 0)) || data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
            //if (amount <= 0 || data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n   ● กรุณาตรวจสอบจำนวนเงิน";
                error = error + 1;
            }

            data = wgGetCellByPosition(htmlRow, 14).innerText;
            if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                err_text = err_text + "\n   ● เหตุผล";
                error = error + 1;
            }

            //alert("2");
            if (error == 0) {
                return true;
            } else {
                alert(err_text);
                return false;
            }

        }

        function WebGrid1_OnEditKeyDown(controlId) {
            //alert(event.keyCode);
            var grid = ISGetObject("WebGrid1");

            var totalRows = grid.TotalRows;
            var totalCells = grid.TotalCells;
            var curRow = grid.GetSelectedObject().rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;

            // if enter key
            if (event.keyCode == 13) {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
                //grid.ExitEdit(1,0,0);
                //return false;
                //var ar = grid.GetSelectedObject().GetRowElement();

                //if (ar.IsAddNewRow) {
                //    ar.commit();
                //}
                //else {
                //    event.keyCode = 40;
                //    keyDown(curRow, curRow + 1, curCell - 1);
                //}
            }

                // if up arrow
            else if (event.keyCode == 38 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                if (totalRows >= 2) {
                    if (curRow > 0) {
                        keyDown(curRow, curRow - 1, curCell - 1);
                    }
                }
            }

                // if down arrow key
            else if (event.keyCode == 40 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
            }
                // if left arrow key
            else if (event.keyCode == 37) {

                if (curCell > 1) {
                    //jq(document).trigger(jq.Event('keydown', { keyCode: 9, shiftKey: true }));
                    //var press = jQuery.Event("keydown");
                    //press.shiftKey = false;
                    //press.which = 9;
                    //jq("WebGrid1").trigger(press);
                    //alert("x");
                    //return;
                    keyDown2(curRow, curCell - 2);

                }
            }
                // if right arrow key
            else if (event.keyCode == 39) {
                //if (curCell < totalCells - 1) {
                event.keyCode = 9;
                //}
            }
            //else if (event.keyCode == 27) {
            //    //alert("esc");
            //    ////column pattern
            //    try{
            //        var row1 = grid.GetSelectedObject().GetRowObject();
            //        //var CmmtDetailCombo1 = ISGetObject("CmmtDetailCombo");
            //        var cmtval1 = row1.GetCells().GetNamedItem("CmmtDetail").Value
            //        //alert(CmtList[cmtval]);
            //        var cells1 = row1.GetCells();

            //        var cmtpat1 = CmtList[cmtval1];
            //        var columnindex = 6;
            //        var cmtarrs = cmtpat1.toString().split(",");

            //        var read_count = 0;
            //        var unitpat = UnitList[cmtval1];
            //        var unitarrs = unitpat.toString().split(",");

            //        for (i = 1; i <= 3; i++) {
            //            if (cmtarrs[i] == '1') {
            //                var patcells = cells1[columnindex];
            //                patcells.SetForceNoEdit(false);

            //                var cellCSS = patcells.GetElement().className;
            //                patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
            //                patcells.GetElement().className += " EditCellColor";
            //                read_count = read_count + 1;
            //            }
            //            else {
            //                var patcells = cells1[columnindex];
            //                patcells.SetForceNoEdit(true);

            //                var cellCSS = patcells.GetElement().className;
            //                patcells.GetElement().className = cellCSS.replace("EditCellColor", "");
            //            }
            //            //alert(unitarrs[i - 1]);
            //            var patcells2 = cells1[columnindex + 1];
            //            //row.GetCells().GetNamedItem("Unit1").SetForceNoEdit(false);
            //            //row.GetCells().GetNamedItem("Unit1").SetText(unitarrs[i - 1], true);
            //            patcells2.SetText(unitarrs[i - 1], true);
            //            patcells2.SetForceNoEdit(true);
            //            columnindex = columnindex + 2;
            //        }
            //        if (read_count == 0) {
            //            var cellCSS = cells1[13].GetElement().className;
            //            cells1[13].SetForceNoEdit(false);
            //            cells1[13].GetElement().className = cellCSS.replace("EditCellColor", "");
            //            cells1[13].GetElement().className += " EditCellColor";
            //        }
            //        else {
            //            cells1[13].SetForceNoEdit(true);
            //            cells1[13].GetElement().className = cellCSS.replace("EditCellColor", "");
            //        }

            //        var df3 = Default3List[cmtval1];
            //        if (df3 > 0) {
            //            row1.GetCells().GetNamedItem("Element3").SetText(df3, true);
            //            row1.GetCells().GetNamedItem("Element3").SetForceNoEdit(true);
            //        }

            //    }
            //    catch (err) { }
            //}


        }

        function keyDown(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.ExitEdit(1, 0, 0);
            grid.SetFocus();

            cell2.Select(true);

            nextRowEl.Select();

            cell1.ActivateEdit();
        }
        function keyDown2(curRow, cell) {
            var grid = ISGetObject("WebGrid1");

            var selectedObject = grid.GetSelectedObject(); // return object of type SelectedObject
            var selectedRow = selectedObject.ToRowObject();
            var cell1 = selectedRow.GetCell(cell);
            grid.SetFocus();
            cell1.Select(true);
            cell1.ActivateEdit();

        }

        function triggerKeyEvents(field, keyCode, shiftKey, ctrlKey) {

            field = $(field);

            shiftKey = Boolean(shiftKey);

            ctrlKey = Boolean(ctrlKey);


            field.simulate("keydown", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

            field.simulate("keypress", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });


            if (field.is(HTML5_TEXT_INPUT_FIELD_SELECTOR)) {

                applyKeyCodeToValue(field, keyCode);

            }


            field.simulate("keyup", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

        }

        function SaveScrollPosition(gridId, action) {
            // collecting the last position
            // of the vertical scrollbar
            // by obtaining the scrollTop property
            var grid = ISGetObject(gridId);
            // obtain the scrollTop and scrollLeft property 
            // of the vertical scrollbar and horizontal scrollbar
            var vl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop + "";
            var hl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft + "";
            // only send the scrollTop property
            // of the server if the action performed
            // by the grid OTFPB is 'Refresh'

            //if (action == "Refresh") {
            // sending over the scrollTop and scrollLeft property
            // to the server by using AddInput method
            grid.AddInput("scrollTopPos", vl);
            grid.AddInput("scrollLeftPos", hl);
            //}

            return true;
        }

        function ApplyLatestScroll(gridId, y, x) {
            // set back the previous scrollTop and scrollLeft property or
            // vertical and horizontal scroll position with 
            // the parameter sent from the server side
            var grid = ISGetObject(gridId);
            // manually configure the vertical and horizontal scroll position
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop = y;
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft = x;

            var cellEl = grid.GetActiveEditCell().ToCellObject();
            grid.SetFocus();
            cellEl.ActivateEdit();
            return true;
        }

        function CustomRequestDel() {
            if (confirm('กรุณายืนยันการลบข้อมูล') == false) {
                return false
            }
            var grid = ISGetObject("WebGrid1");
            var table = grid.GetRootTable();
            var checkedRows = table.GetCheckedRows();

            if (checkedRows.length == 0) {
                alert("Please check an item.");
                setTimeout(function () { grid.SetFocus(); }, 10);
            }
            else {

                grid.AddInput("type", "2");
                grid.SendCustomRequest();

            }

            event.cancelBubble = true;
            event.returnValue = false;
        }

        function CustomRequestCopy() {
            if (confirm('กรุณายืนยันการคัดลอกข้อมูล') == false) {
                return false
            }
            var grid = ISGetObject("WebGrid1");
            var table = grid.GetRootTable();
            var checkedRows = table.GetCheckedRows();

            if (checkedRows.length == 0) {
                alert("Please check an item.");
                setTimeout(function () { grid.SetFocus(); }, 10);
            }
            else {

                grid.AddInput("type", "1");
                grid.SendCustomRequest();

            }

            event.cancelBubble = true;
            event.returnValue = false;
        }
        // This function is invoked when the custom request is about to be made.
        function wgPrepareCustomAction(grid, xmlr, name) {
            grid.SetStatus1("Processing...");
            return true;
        }
        var exp = '0';
        function WebTreeView3_Expand() {
            exp = '1';
            var combo = ISGetObject("WebCombo3");
            combo.SetFocus();
            combo.ShowDropDown();
        }
        function WebTreeView3_Collapse() {
            exp = '1';
            var combo = ISGetObject("WebCombo3");
            combo.SetFocus();
            combo.ShowDropDown();
        }
        function WebCombo3_Hide() {
            if (exp == '1') {
                exp = '0';
                var combo = ISGetObject("WebCombo3");
                combo.SetFocus();
                combo.ShowDropDown();
            }
        }

        var gridedit = 0;

        function WebGrid1_OnKeyDown(controlId) {
            var grid = ISGetObject("WebGrid1");

            // if enter key
            if (event.keyCode == 27) {
                if (gridedit == 1) {
                    grid.ExitEditMode(true);
                    gridedit = 0;
                }
                else {
                    return false;
                }
            }
        }

        function WebGrid1_OnEnterEditMode(controlId) {
            gridedit = 1;
        }

        function SaveClick() {

            var grid = ISGetObject("WebGrid1");
            try {
                var savecheck = grid.ExitEdit(1, 0, 0);
                if (savecheck[0] == true) {
                    __doPostBack('PostBackBtn', '')
                }
            }
            catch (err) { }
        }

        function WebGrid1_OnAfterAdd(controlId) {
            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            if (dfc != 'null') {
                row.GetCells().GetNamedItem("FundCenter").SetText(dfcname, true);
                row.GetCells().GetNamedItem("FundCenter").SetValue(dfc);
            }
        }
        function DownloadClick(atCode, planYear) {
                window.open('DownloadTamplate.aspx?cmmt_Code=' + atCode + '&PlanYear=' + planYear);
        }
    </script>
    <style>
        .WC4-DD-N {
            height: 0px;
        }

        .WC4-DD-A {
            height: 0px;
        }
    </style>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="margin-left: 10px; padding: 10px 10px 10px 10px;">
        <div style="float: left; width: 97%; border: solid; border-color: gray; border-width: 1px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; text-align: right; padding: 5px 5px 5px 5px;">
            <div style="text-align: right; margin-top: 5px;">
                <div align="left" style="width: 600px; float: left">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </div>

                ปี&nbsp;
            <asp:TextBox ID="PlanYearsTxt" runat="server" Width="50px" Enabled="false" Style="text-align: center;"></asp:TextBox>
                &nbsp;&nbsp;&nbsp;&nbsp;
            Version&nbsp;
            <asp:TextBox ID="VersionTxt" runat="server" Width="30px" Enabled="false" Style="text-align: center"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" title="เลือกหน่วยงานและโครงการที่ต้องการ จากนั้นคลิกที่ปุ่มนี้เพื่อทำการค้นหา">
                <asp:ImageButton ID="SearhBtn" runat="server" ImageUrl="Icons/search.jpg" OnClientClick="clickedx()" /></a>
                &nbsp;&nbsp;<a href="#" title="เลือกรายการที่ต้องการ จากนั้นคลิกปุ่มนี้เพิ่อทำการคัดลอกรายการ"><asp:ImageButton ID="coppy_btn" runat="server" ImageUrl="Icons/copy.jpg" OnClientClick="CustomRequestCopy(); return false" /></a>
                &nbsp;&nbsp;<a href="#" title="เลือกรายการที่ต้องการ จากนั้นคลิกปุ่มนี้เพิ่อทำการลบรายการ"><asp:ImageButton ID="delete_btn" runat="server" ImageUrl="Icons/delete.jpg" OnClientClick="CustomRequestDel(); return false" /></a>
                &nbsp;&nbsp;<asp:ImageButton ID="SaveBtn" runat="server" ImageUrl="Icons/save.jpg" Style="height: 21px" OnClientClick="SaveClick(); return false;" /><asp:Button ID="PostBackBtn" runat="server" Text="" Width="0px" Height="0px" Visible="false"  />
                &nbsp;
            </div>
        </div>
        <div>
            <div id="div1" runat="server" style="float: left; width: 40%; border: solid; border-color: gray; border-width: 1px; margin-right: 10px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">

                <div style="padding-bottom: 5px;"><strong>&nbsp;FundCenter</strong></div>


                <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" Height="30px" Width="100%" EnableTheming="True">
                    <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="ตั้งแต่ ถึง">
                        <ContentTemplate>
                            <table>
                                <tr>
                                    <td>ตั้งแต่</td>
                                    <td>
                                       <ISWebCombo:WebCombo ID="WebCombo1" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>
                                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByUser" TypeName="BasicDataTableAdapters.FCTR_Child2TableAdapter">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="username" SessionField="users" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>
                                    </td>
                                    <td>ถึง</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo2" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>
                                        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByUser" TypeName="BasicDataTableAdapters.FCTR_Child2TableAdapter">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="username" SessionField="users" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>
                                    </td>
                                </tr>
                            </table>

                        </ContentTemplate>
                    </asp:TabPanel>
                    <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="เลือกเอง">
                        <ContentTemplate>
                            <div style="margin-left: 30px; color: gray; font-size: 11px;">
                                <ISWebCombo:WebCombo ID="WebCombo3" runat="server" UseDefaultStyle="True" Width="350px" DataTextField="pathname" DataValueField="Fundcenter_FundcenterCode" AllowWildCardSearch="true" DropDownRows="100000">
                                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false">
                                    </LayoutSettings>                                    
                                </ISWebCombo:WebCombo>
                                &nbsp;(รวมหน่วยงานใต้สังกัด)
                            </div>
                        </ContentTemplate>
                    </asp:TabPanel>
                </asp:TabContainer>
            </div>
            <div id="div3" runat="server" style="float: right; width: 55%; border: solid; border-color: #a0a0a0; border-width: 1px; margin-right: 30px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">
                &nbsp;
                <strong>Commitment Item</strong>
                <asp:TabContainer ID="TabContainer2" runat="server" ActiveTabIndex="0" Height="30px" Width="98%" EnableTheming="True">
                    <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="ตั้งแต่ ถึง">
                        <ContentTemplate>
                            <table>
                                <tr>
                                    <td>ตั้งแต่</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo4" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="CmmtCode" Height="20px" OnInitializeDataSource="WebCombo4_InitializeDataSource" AdditionalSearchFields="CmmtCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ CommitmentItem" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="CmmtCode" Name="CmmtCode" HeaderText="รหัส CommitmentItem" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                                    </td>
                                    <td>ถึง</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo5" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="CmmtCode" Height="20px" OnInitializeDataSource="WebCombo5_InitializeDataSource" AdditionalSearchFields="CmmtCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ CommitmentItem" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="CmmtCode" Name="CmmtCode" HeaderText="รหัส CommitmentItem" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>

                                    </td>
                                </tr>
                            </table>

                        </ContentTemplate>
                    </asp:TabPanel>
                    <asp:TabPanel ID="TabPanel4" runat="server" HeaderText="เลือกเอง">
                        <ContentTemplate>
                            <div style="margin-left: 10px; color: gray; font-size: 11px;">
                                <asp:HiddenField runat="server" ID="hdf2" />
                                <asp:ListBox ID="ms9" runat="server" Width="97%" SelectionMode="Multiple"></asp:ListBox>
                            </div>
                        </ContentTemplate>
                    </asp:TabPanel>
                </asp:TabContainer>

            </div>
            <div id="div2" runat="server" style="float: right; width: 97%; border: solid; border-color: gray; border-width: 1px; margin-right: 30px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">
                <div runat="server" id="fil_name" style="padding-bottom: 5px;"><strong>โครงการ</strong></div>
                <div style="margin: 5px 5px 5px 5px;">
                    <asp:HiddenField runat="server" ID="hdf1" />
                    <asp:ListBox ID="ms8" runat="server" Width="97%" SelectionMode="Multiple"></asp:ListBox><br />
                </div>
                <script type="text/javascript">
                    $(document).ready(function () {

                        var ms7 = $('#<%= ms8.ClientID%>').magicSuggest({
                            // will fetch data from options
                        });
                        var ms10 = $('#<%= ms9.ClientID%>').magicSuggest({
                        });
                        clickedx = function () {

                            $("#<%= hdf1.ClientId %>").val(ms7.getValue());
                            $("#<%= hdf2.ClientId %>").val(ms10.getValue());
                        }
                    });
                </script>
            </div>
            <div style="float: left; width: 97%; border: solid; border-color: gray; border-width: 1px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">

                <div runat="server" id="grid_name" style="padding-bottom: 5px;"><strong>ค่าใช้จ่ายอื่น-โครงการ</strong></div>


                <ISWebGrid:WebGrid ID="WebGrid1" runat="server" UseDefaultStyle="True" Width="100%" OnAddRow="WebGrid1_AddRow" OnUpdateRow="WebGrid1_UpdateRow" DefaultStyleMode="Silver" OnInitializePostBack="WebGrid1_InitializePostBack" Height="350px" OnInitializeRow="WebGrid1_InitializeRow">
                    <LayoutSettings AllowAddNew="Yes" EditOnClick="True" AllowColumnMove="No"
                        AllowEdit="Yes" AllowDelete="Yes" AllowSorting="Yes" ColumnFooters="Yes" NewRowLostFocusAction="AlwaysUpdate"
                        ResetNewRowValuesOnError="False" InProgressUIBehavior="ChangeCursorToHourGlass"
                        AlwaysShowHelpButton="false" PagingMode="ClassicPaging" PagingSize="10"
                        VirtualLoadMode="LargeData" AllowGrouping="Yes" ColumnFooterAggregateMode="CalculateAllData"
                        AllowExport="Yes"
PagingExportMode="ExportAllData"
VirtualPageSize="500">
                        <RowStyle Font-Names="Tahoma" Font-Size="9" CustomRules="overflow: hidden;" />
                        <AlternatingRowStyle Font-Names="Tahoma" Font-Size="9" BackColor="#fbfbfb" CustomRules="overflow: hidden;" />
                        <ClientSideEvents OnBeforeRowSelect="OnBeforeRowSelect" OnRowValidate="WebGrid1_OnRowValidate" OnRowContextMenu="WebGrid1_OnRowContextMenu" OnRowSelect="OnRowSelect" OnAfterExitEditMode="WebGrid1_OnAfterExitEditMode" OnEditKeyDown="WebGrid1_OnEditKeyDown" OnKeyDown="WebGrid1_OnKeyDown" OnEnterEditMode="WebGrid1_OnEnterEditMode" OnAfterResponseProcess="DisableCheck" OnAfterAdd="WebGrid1_OnAfterAdd" />
                    </LayoutSettings>
                    <RootTable DataKeyField="Id" NewRowInfoText="เพิ่มรายการ">
                        <Columns>
                            <ISWebGrid:WebGridColumn IsRowChecker="true" Name="checker">
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Caption="Fund Center" Name="FundCenter" DataMember="FundCenter_FundCenterCode" Width="100px" EditType="WebComboNET" WebComboID="FundCenterCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="Description" DataSourceID="FundCenterDataSource"
                                    DataValueField="FundCenter_FundCenterCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="CommitmentItem" Width="150px" Caption="Commitment Item" DataMember="Cmmt_CmmtCode" EditType="WebComboNET" WebComboID="CmmtCombo" IsAutoWidth="true">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="Description" DataSourceID="CmmtDataSource"
                                    DataValueField="Cmmt_CmmtCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="CmmtDetail" Width="100px" Caption="รายการ" DataMember="CmmtDetail_Id" EditType="WebComboNET" WebComboID="CmmtDetailCombo" IsAutoWidth="true">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="Description" DataSourceID="CmmtDetailataSource"
                                    DataValueField="CmmtDetail_Id">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Project" Width="120px" Caption="โครงการ" DataMember="Project_ProjectCode" EditType="WebComboNET" WebComboID="ProjectCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="Description" DataSourceID="ProjectDataSource"
                                    DataValueField="Project_ProjectCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Identification" Width="100px" Caption="กิจกรรม" DataMember="Identification" IsAutoWidth="True">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Element1" Width="80px" Caption="จำนวน" DataMember="Element1" DataFormatString="##,##0.##">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Unit1" Width="60px" Caption="หน่วย" DataMember="ElementUnit1">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Center" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Element2" Width="80px" Caption="ระยะเวลา" DataMember="Element2" DataFormatString="##,##0.##">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Unit2" Width="60px" Caption="หน่วย" DataMember="ElementUnit2">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Center" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Element3" Width="80px" Caption="อัตรา" DataMember="Element3" DataFormatString="##,##0.00">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Unit3" Width="60px" Caption="หน่วย" DataMember="ElementUnit3">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Center" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="SumEl" Width="70px" Caption="จำนวนเงิน" DataMember="SumEl" DataFormatString="##,##0.00" FooterText="รวม">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Amount" Width="90px" Caption="จำนวนเงินที่เสนอขอตั้งงบประมาณ" DataMember="Amount" AggregateFunction="Sum" DataFormatString="##,##0.00">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" BackColor="#ffba53" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="Note" Width="200px" Caption="เหตุผล" DataMember="Note" IsAutoWidth="True" HiddenDataMember="readonly_flag">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Caption=" " ColumnType="Template" Name="Attachment" Width="50px">
                                <CellTemplate>
                                    <a href="#" style="text-decoration: none; border: none;" onclick="popupattach1()">
                                        <img src="a0.jpg" height="16px" style="text-decoration: none; border: none;" />
                                    </a>
                                    <a href="#" style="text-decoration: none; border: none;" onclick="popupattach1()">
                                        <label><b><%# Eval("attachments_amount")%></b></label>
                                    </a>
                                </CellTemplate>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Caption=" " ColumnType="Template" Name="DownloadTemplate" Width="30px">
                                <CellTemplate>
                                    <%--<input type="hidden" id="hddTemplateName" runat="server" value='<%# Eval("TemplateName")%>' />
                                    <a href="#" style="text-decoration: none; border: none;">--%>
                                    <img src="Images/Icons/excel.png" height="16" id="imgTemplate" style="text-decoration: none; border: none; cursor:pointer" title="ดาวน์โหลด Template" runat="server" onclick='<%# "DownloadClick(" + Eval("Cmmt_CmmtCode").ToString() + ", " + Eval("PlanYear").ToString() + ");" %>' visible='<%# Eval("TemplateName").ToString() <> ""  %>' />
                                <%--</a>--%>
                                </CellTemplate>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="readonly_flag" Width="100px" Caption="readonly_flag" DataMember="readonly_flag" EditType="NoEdit" Visible="false">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                            </ISWebGrid:WebGridColumn>
                        </Columns>
                    </RootTable>
                    <CustomEditors>
                        <ISWebGrid:WebGridCustomEditor ControlType="DHTMLClientControl" JavascriptFiles="Calculator.js" Name="Calculator" Persistence="DesignerLevel" ScriptFolder="EditorsPack1">
                            <Behavior DropdownButtonImageFile="CalcDD.gif" HasDropdownButton="True" />
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor ControlType="DHTMLClientControl" JavascriptFiles="NumericUpDown.js" Name="NumericUpDown" Persistence="DesignerLevel" ScriptFolder="EditorsPack1">
                            <Behavior HasDropdownButton="True" />
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor JavascriptFiles="RichTextBox.js" Name="RichTextBox" Persistence="DesignerLevel" ScriptFolder="EditorsPack1" ServerControlFullName="Telerik.WebControls.RadEditor">
                            <Behavior BaseEditorType="Custom" DropdownButtonType="Custom" HasDropdownButton="True" />
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor JavascriptFiles="WebInputNET.js" Name="WebInputNET" Persistence="DesignerLevel" ScriptFolder="WebInput" ServerControlFullName="ISNet.WebUI.WebControls.WebInput">
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor ControlType="DHTMLClientControl" JavascriptFiles="SlideBar.js" Name="Slidebar" Persistence="DesignerLevel" ScriptFolder="EditorsPack2">
                            <Behavior DropdownButtonImageFile="SliderDD.gif" HasDropdownButton="True" />
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor ControlType="DHTMLClientControl" JavascriptFiles="HtmlEditor.js" Name="HtmlEditor" Persistence="DesignerLevel" ScriptFolder="EditorsPack2">
                            <Behavior BaseEditorType="Custom" />
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor ControlType="DHTMLClientControl" DependencyFiles="SmartWebResources\S\WebScheduler_Calendar.js\301000" JavascriptFiles="VistaCalendar.js;VistaCalendar.css" Name="VistaCalendar" Persistence="DesignerLevel" ScriptFolder="EditorsPack3">
                            <Behavior DropdownButtonImageFile="VistaCalendar.gif" HasDropdownButton="True" SupportElegantStyles="True" />
                        </ISWebGrid:WebGridCustomEditor>
                        <ISWebGrid:WebGridCustomEditor JavascriptFiles="WebTextEditor.js" Name="WebTextEditor" Persistence="DesignerLevel" ScriptFolder="EditorsPack3" ServerControlFullName="ISNet.WebUI.WebTextEditor.WebTextEditor">
                            <Behavior BaseEditorType="Custom" />
                        </ISWebGrid:WebGridCustomEditor>
                    </CustomEditors>
                </ISWebGrid:WebGrid>
                <ISWebCombo:WebCombo ID="FundCenterCombo" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" Width="200px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true" OnValueChanged="FundCenterCombo_ValueChanged">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns">
                        <ClientSideEvents OnAfterItemSelected="FundCenterCombo_OnAfterItemSelected" />
                    </LayoutSettings>
                    <Columns>
                        <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                        <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                    </Columns>
                </ISWebCombo:WebCombo>
                <ISWebCombo:WebCombo ID="CmmtCombo" runat="server" UseDefaultStyle="true" DataTextField="Description" DataValueField="CmmtCode" DropDownRows="100000" AdditionalSearchFields="CmmtCode" AllowWildCardSearch="true" >
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns">
                        <ClientSideEvents OnAfterItemSelected="CmmtCombo_OnAfterItemSelected" />
                        <TextSettings ParentEmptyPromptText="กรุณาเลือก FundCenter" />
                    </LayoutSettings>
                    <Columns>
                        <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="CommitmentItem" Width="250px" />
                        <ISWebCombo:WebComboColumn BaseFieldName="CmmtCode" Name="FundCenterCode" HeaderText="รหัส CommitmentItem" Width="80px" />
                    </Columns>
                    <LinkSettings Enabled="True" ParentWebComboID="FundCenterCombo" />
                </ISWebCombo:WebCombo>
                <ISWebCombo:WebCombo ID="CmmtDetailCombo" runat="server" UseDefaultStyle="true" DataTextField="Description" DataValueField="Id" Height="20px" Width="200px" AllowWildCardSearch="true" DropDownRows="100000">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns">
                        <ClientSideEvents OnAfterItemSelected="CmmtDetailCombo_OnAfterItemSelected" />
                                   <TextSettings ParentEmptyPromptText="กรุณาเลือก Commitment Item" />
                    </LayoutSettings>
                    <Columns>
                        <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อรายการ" Width="250px" />
                        <ISWebCombo:WebComboColumn BaseFieldName="ItemNo" Name="ItemNo" HeaderText="ลำดับ" Width="30px" />
                    </Columns>
                    <LinkSettings Enabled="True" ParentWebComboID="CmmtCombo" />
                </ISWebCombo:WebCombo>
                <ISWebCombo:WebCombo ID="ProjectCombo" runat="server" UseDefaultStyle="true" DataTextField="Description" DataValueField="ProjectCode" AdditionalSearchFields="ProjectCode" AllowWildCardSearch="true">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns" >
                        <TextSettings ParentEmptyPromptText="กรุณาเลือก FundCenter" />
                    </LayoutSettings>
                    <Columns>
                        <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อโครงการ/งานสนับสนุน" Width="250px" />
                        <ISWebCombo:WebComboColumn BaseFieldName="ProjectCode" Name="FundCenterCode" HeaderText="รหัสโครงการ/งานสนับสนุน" Width="80px" />
                    </Columns>
                    <LinkSettings Enabled="True" ParentWebComboID="FundCenterCombo" />
                </ISWebCombo:WebCombo>


            </div>
        </div>
    </div>
    <br />
    <br />
    <ISWebTreeView:WebTreeView ID="WebTreeView1" runat="server" Height="265px" Width="235px" Visible="false">
        <NodeSettings EnableAnimation="True" />
    </ISWebTreeView:WebTreeView>
    <ISWebTreeView:WebTreeView ID="WebTreeView2" runat="server" Height="265px" Width="235px" Visible="false">
        <NodeSettings EnableAnimation="True" />
    </ISWebTreeView:WebTreeView>
    <ISWebTreeView:WebTreeView ID="WebTreeView3" runat="server" Height="265px" Width="235px" Visible="false">
        <NodeSettings EnableAnimation="True" />

    </ISWebTreeView:WebTreeView>
    <asp:ObjectDataSource ID="FundCenterDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="BasicDataTableAdapters.FCTR_ValueTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="CmmtDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="BasicDataTableAdapters.Cmmts_ValueTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
            <asp:Parameter DefaultValue="F03" Name="FormId" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="CmmtDetailataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="BasicDataTableAdapters.CmmtDetails_ValueTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
            <asp:Parameter DefaultValue="F03" Name="FormId" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ProjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="BasicDataTableAdapters.Project_Value2TableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <script>
        function WebGrid_GetTotalRowCount() {

            try {

                var grid = ISGetObject("WebGrid1")
                if (grid == null || grid.RootTable == null) { alert(grid); return 0; }

                // NOTE: This is done because Intersoft doesn't return the TotalRows accurately for a WebGrid using BatchUpdate
                var rowCount = 0;
                while (true) {
                    var row = grid.RootTable.GetRow(rowCount)
                    if (row == null) { return rowCount; }
                    rowCount++;
                }
                //alert(rowCount);
            }
            catch (ex) {
                ShowJSException(ex);

            }
        }

        function DisableCheck() {
            try{
            var rowcount = WebGrid_GetTotalRowCount();
            var WebGrid1 = ISGetObject("WebGrid1");
            var rowCheckerElm = WebGrid1.RootTable.GetElement(WG40.COLHEADER, WG40.HTMLTABLE).cells[1].childNodes[0].childNodes[0].childNodes[0];

            if (rowcount == 0) {
                rowCheckerElm.checked = false;
                rowCheckerElm.disabled = true;


                return true;
            } else {
                rowCheckerElm.disabled = false;

            }
            } catch (err) { }
        }
        DisableCheck();
    </script>

</asp:Content>

